<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="page" %>
<page:page>
    <!--获取url的参数-->
    <script src="../app/js/getUrlParam.js"></script>
    <!--分页-->
    <script src="page.js"></script>

    <div class="row">
        <!-- 顶部查询  -->
        <div class="col-lg-12  page-header">
            <div class="col-md-1"></div>
            <div class="col-md-3">
                <div class="form-group">
                    <span for="search_mobile">手机号</span>
                    <span>
                    <input type="text" class="form-control " name="search_mobile" id="search_mobile" size="20"
                           maxlength="50"/>
                </span>
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <span for="search_nickname">昵称</span>
                    <span>
                        <input type="text" class="form-control " name="search_nickname" id="search_nickname" size="20"
                               maxlength="50"/>
                </span>
                </div>
            </div>
            <div class="col-md-2" style="padding-top: 20px;">
                <div class="form-group">
                    <button type="button" class="btn btn-outline btn-primary btn-sm" onclick="searchDriver()"><i
                            class="fa fa-search"></i>&nbsp;查询
                    </button>
                </div>
            </div>
        </div>
        <!--列表开始-->
        <div class="col-lg-12">
            <div class="datagrid_container" style="margin-top: 10px;">
                <!-- /.row -->
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            司机信息
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                    <tr>
                                        <th>司机id</th>
                                        <th>手机号</th>
                                        <th>昵称</th>
                                        <th>接单数</th>
                                        <th>评价得分</th>
                                        <th>流水金额</th>
                                        <th>账户余额</th>
                                        <th>查看流水明细</th>
                                        <th>提现</th>
                                        <th>司机信息详情</th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody">
                                    </tbody>
                                </table>
                            </div>


                            <!-- /.table-responsive -->
                            <div class="row">
                                <div class="col-sm-2" style="padding-top: 25px">
                                    <div class="dataTables_length">
                                        <select name="dataTables-example_length" onchange="pageCount()"
                                                id="dataTables-example_length" aria-controls="dataTables-example"
                                                class="form-control input-sm">
                                            <option value="10">每页10行</option>
                                            <option value="25">每页25行</option>
                                            <option value="50">每页50行</option>
                                            <option value="100">每页100行</option>
                                        </select>
                                    </div>

                                </div>
                                <div class="col-sm-3" style="padding-top: 30px">

                                    <div class="dataTables_info" id="dataTables-example_info" role="status"
                                         aria-live="polite"></div>
                                </div>

                                <div class="col-sm-6">
                                    <div class="dataTables_paginate paging_simple_numbers"
                                         id="dataTables-example_paginate">
                                        <ul class="pagination" id="paginationPage">
                                            <li class="page active" class="paginate_button"
                                                aria-controls="dataTables-example"
                                                tabindex="0"><a href="#">1</a></li>
                                            <li class="page" class="paginate_button " aria-controls="dataTables-example"
                                                tabindex="1"><a href="#">2</a></li>
                                            <li class="page" class="paginate_button " aria-controls="dataTables-example"
                                                tabindex="2"><a href="#">3</a></li>
                                            <li class="page" class="paginate_button " aria-controls="dataTables-example"
                                                tabindex="3"><a href="#">4</a></li>
                                            <li class="page" class="paginate_button " aria-controls="dataTables-example"
                                                tabindex="4"><a href="#">5</a></li>
                                            <li class="page" class="paginate_button " aria-controls="dataTables-example"
                                                tabindex="5"><a href="#">6</a></li>

                                        </ul>
                                        <ul class="pagination">
                                            <li class="paginate_button next" aria-controls="dataTables-example"
                                                tabindex="0" id="dataTables-example_next"><a href="#"
                                                                                             onclick="onPage(this)">Next</a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->

                <!-- /.row -->
            </div>
        </div>
        <!--列表结束-->
    </div>

    <!-- /提现.modal -->
    <div class="modal fade" id="withdrawals">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">提取现金</h4>
                </div>
                <div class="modal-body" style="overflow: auto">

                    <div id='withdrawals_body'>
                        <form id="withdrawals_from">
                            <div class="col-lg-12">
                                <div class="col-sm-6" class="form-group">
                                    <span for="mobile_w">手机号</span>
                                    <span>
                                     <input type="text" class="form-control " name="mobile_w" id="mobile_w" size="20"
                                            maxlength="50" disabled required="ture"/>
                                </span>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group">
                                        <span for="balance_w">账户余额</span>
                                        <span>
                                        <input type="text" class="form-control " name="balance_w" id="balance_w"
                                               size="20" maxlength="50" disabled required="ture"/>
                                    </span>
                                    </div>
                                </div>
                            </div>

                            <div class="col-lg-12">
                                <div class="col-sm-6" class="form-group">
                                    <span for="money_w">提现金额</span>
                                    <span>
                                     <input type="text" class="form-control " name="money_w" id="money_w" size="20"
                                            maxlength="50" required="ture"/>
                                </span>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group">
                                        <span for="operator_w">操作人</span>
                                        <span>
                                        <input type="text" class="form-control " name="operator_w" id="operator_w"
                                               size="20" maxlength="50" required="ture"/>
                                    </span>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <button type="submit" class="btn btn-primary" style="display: none">确定</button>
                            </div>
                        </form>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="$('form#withdrawals_from').submit()">确定
                    </button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /提现.modal -->
    <script>
        function searchDriver() {
            queryList($('.active').attr("tabindex"), $("#dataTables-example_length").val());
        }

        function queryList(page, size) {
            var params = new Object();
            params.size = size;
            params.page = page;
            params.mobile = $('#search_mobile').val();
            params.nickname = $('#search_nickname').val();
            $.ajax({
                url: '${pageContext.request.contextPath}/v1/driver/driver/like/search',
                type: 'POST',
                datatype: 'json',
                contentType: 'application/json;charset=utf-8',
                Accept: 'application/json',
                data: JSON.stringify(params),
                cache: false,
                success: function (data, textStatus, jqXHR) {
                    $("#tbody").empty();
                    $(data.data).each(function () {
                        var data1 = this;
                        $("#tbody").append('<tr class="odd gradeX" id=' + this.userId + ' item=' + JSON.stringify(this) + '>' +
                            '<td class="center">' + this.userId + '</td>' +
                            '<td class="center">' + this.mobile + '</td>' +
                            '<td class="center">' + this.nickName + '</td> ' +
                            '<td class="center">' + this.orderNum + '</td> ' +
                            '<td class="center">' + this.score + '</td>' +
                            '<td class="center">' + this.turnover + '</td>' +
                            '<td class="center">' + this.money + '</td>' +
                            '<td class="center"><a class = "fa fa-search queryOne" onclick="queryOne(\'' + this.userId + '\')" ></a></td>' +
                            '<td class="center"><a class = "fa fa-dollar queryOne"   href="#withdrawals" data-toggle="modal" onclick="withdrawals(\'' + this.userId + '\')" ></a></td>' +
                            '<td class="center"><a class = "fa fa-user" href=' + this.userId + '"../linbike/driverInformation.jsp?driverId="></a></td>' +
                            '</tr>').data("item", this);
                        $("#" + this.userId).attr("item", JSON.stringify(this));//直接写item属性,json串里的空格会把this分成不完整的json串,所以改为直接set值
                    });

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    $('#result').text(errorThrown);
                }
            });
        }

        function queryOne(driverId) {
            window.open('${pageContext.request.contextPath}/app/driverTradeLogInfo.html?driverId=' + driverId, "window", "width=800px,height=600px, modal=yes,status=no");
        }

        function withdrawals(driverId) {
            var str = $("#" + driverId).attr("item");
            var data = JSON.parse(str);
            $("#mobile_w").val(data.mobile);
            $("#balance_w").val(data.money);
            $("#money_w").val("");
            $("#operator_w").val("");
        }

        $(function () {
            $("form#withdrawals_from").submit(function (e) {
                e.preventDefault();
                var mobile = $("#mobile_w").val();
                var money = $("#money_w").val();
                var operator = $("#operator_w").val();

                if (money == null || money == "" || operator == null || operator == "") {
                    alert("所填内容不可为空");
                    return;
                }
                var reg = new RegExp("^[0-9]*$");
                if (!reg.test(money)) {
                    alert("提现金额请输入数字!");
                    return;
                }
                if (money * 1 > $("#balance_w").val() * 1) {
                    alert("提现金额超出账户余额!");
                    return;
                }

                var params = new Object();
                params.mobile = mobile;
                params.money = money;
                params.operator = operator;
                $("#params").val(JSON.stringify(params));
                $.ajax({
                    url: "${pageContext.request.contextPath}/v1/driver/driver/withdrawals",
                    type: 'POST',
                    datatype: 'json',
                    contentType: 'application/json;charset=utf-8',
                    Accept: 'application/json',
                    data: JSON.stringify(params),
                    cache: false,
                    success: function (data, textStatus, jqXHR) {
                        if (data.errorCode == 0) {
                            $('#withdrawals').modal('hide');//model的关闭事件
                            alert("操作成功");
                            searchDriver();
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert("发布失败，请重新上传!");
                        $('#result').text(errorThrown);
                    }
                });

                e.preventDefault(); //STOP default action
                $(this).unbind(e);
            });
        })
    </script>
</page:page>